<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>Tcl_DetachPids manual page - Library Procedures</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tcl C API</a> <small>&gt;</small> DetachPids</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<DL>
<DD><A HREF="DetachPids.htm#M2" NAME="L197">NAME</A>
<DL><DD>Tcl_DetachPids, Tcl_ReapDetachedProcs, Tcl_WaitPid &mdash; manage child processes in background</DD></DL>
<DD><A HREF="DetachPids.htm#M3" NAME="L198">SYNOPSIS</A>
<DL>
<DD><B>#include &lt;tcl.h&gt;</B>
<DD><B>Tcl_DetachPids</B>(<I>numPids, pidPtr</I>)
<DD><B>Tcl_ReapDetachedProcs</B>()
<DD>Tcl_Pid
<DD><B>Tcl_WaitPid</B>(<I>pid, statusPtr, options</I>)
</DL>
<DD><A HREF="DetachPids.htm#M4" NAME="L199">ARGUMENTS</A>
<DL class="arguments">
</DL>
<DD><A HREF="DetachPids.htm#M5" NAME="L200">DESCRIPTION</A>
<DD><A HREF="DetachPids.htm#M6" NAME="L201">KEYWORDS</A>
</DL>
<H3><A NAME="M2">NAME</A></H3>
Tcl_DetachPids, Tcl_ReapDetachedProcs, Tcl_WaitPid &mdash; manage child processes in background
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>#include &lt;tcl.h&gt;</B><BR>
<B>Tcl_DetachPids</B>(<I>numPids, pidPtr</I>)<BR>
<B>Tcl_ReapDetachedProcs</B>()<BR>
Tcl_Pid<BR>
<B>Tcl_WaitPid</B>(<I>pid, statusPtr, options</I>)<BR>
<H3><A NAME="M4">ARGUMENTS</A></H3>
<DL class="arguments">
<DT>int <B>numPids</B> (in)<DD>
Number of process ids contained in the array pointed to by <I>pidPtr</I>.
<P><DT>int <B>*pidPtr</B> (in)<DD>
Address of array containing <I>numPids</I> process ids.
<P><DT>Tcl_Pid <B><A HREF="../TclCmd/pid.htm">pid</A></B> (in)<DD>
The id of the process (pipe) to wait for.
<P><DT>int <B>*statusPtr</B> (out)<DD>
The result of waiting on a process (pipe). Either 0 or ECHILD.
<P><DT>int <B><A HREF="../TkCmd/options.htm">options</A></B> (in)<DD>
The options controlling the wait. WNOHANG specifies not to wait when
checking the process.
<P></DL>
<H3><A NAME="M5">DESCRIPTION</A></H3>
<B>Tcl_DetachPids</B> and <B>Tcl_ReapDetachedProcs</B> provide a
mechanism for managing subprocesses that are running in background.
These procedures are needed because the parent of a process must
eventually invoke the <B>waitpid</B> kernel call (or one of a few other
similar kernel calls) to wait for the child to exit.  Until the
parent waits for the child, the child's state cannot be completely
reclaimed by the system.  If a parent continually creates children
and doesn't wait on them, the system's process table will eventually
overflow, even if all the children have exited.
<P>
<B>Tcl_DetachPids</B> may be called to ask Tcl to take responsibility
for one or more processes whose process ids are contained in the
<I>pidPtr</I> array passed as argument.  The caller presumably
has started these processes running in background and does not
want to have to deal with them again.
<P>
<B>Tcl_ReapDetachedProcs</B> invokes the <B>waitpid</B> kernel call
on each of the background processes so that its state can be cleaned
up if it has exited.  If the process has not exited yet,
<B>Tcl_ReapDetachedProcs</B> does not wait for it to exit;  it will check again
the next time it is invoked.
Tcl automatically calls <B>Tcl_ReapDetachedProcs</B> each time the
<B><A HREF="../TclCmd/exec.htm">exec</A></B> command is executed, so in most cases it is not necessary
for any code outside of Tcl to invoke <B>Tcl_ReapDetachedProcs</B>.
However, if you call <B>Tcl_DetachPids</B> in situations where the
<B><A HREF="../TclCmd/exec.htm">exec</A></B> command may never get executed, you may wish to call
<B>Tcl_ReapDetachedProcs</B> from time to time so that background
processes can be cleaned up.
<P>
<B>Tcl_WaitPid</B> is a thin wrapper around the facilities provided by
the operating system to wait on the end of a spawned process and to
check a whether spawned process is still running. It is used by
<B>Tcl_ReapDetachedProcs</B> and the channel system to portably access
the operating system.

<H3><A NAME="M6">KEYWORDS</A></H3>
<A href="../Keywords/B.htm#background">background</A>, <A href="../Keywords/C.htm#child">child</A>, <A href="../Keywords/D.htm#detach">detach</A>, <A href="../Keywords/P.htm#process">process</A>, <A href="../Keywords/W.htm#wait">wait</A>
<div class="copy">Copyright &copy; 1989-1993 The Regents of the University of California.
<BR>Copyright &copy; 1994-1996 Sun Microsystems, Inc.
</div>
</BODY></HTML>
